home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Examples / Class1.e < prev    next >
Encoding:
Text File  |  2002-10-28  |  3.2 KB  |  123 lines

  1. OPT PREPROCESS
  2.  
  3. MODULE 'feelin','libraries/feelin','a4'
  4.  
  5. PROC main()
  6.    DEF c,w,
  7.        cc:PTR TO feelinClass
  8.  
  9.    sys_SGlob()
  10.  
  11.    IF feelinbase := OpenLibrary('feelin.library',FV_VERSION)
  12. /*
  13. Create the new custom class with a call to F_CreateClass().
  14.  
  15. This function returns a feelinClass structure. You must use class.id as  ID
  16. to  create  instance  of  your  custom class. This ID is unique and made by
  17. F_CreateClass() when ID is NIL.
  18. */
  19.       IF cc := F_CreateClassA([FA_SuperID,     FC_Area,
  20.                                FA_Dispatcher,  {myDispatcher},
  21.                                NIL])
  22.  
  23.          c := ClientObject,
  24.             FA_Client_Title,       'Class1',
  25.             FA_Client_Version,     '$VER: Class1 1.00 (03-08-02)',
  26.             FA_Client_Copyright,   '©2002, Olivier Laviale',
  27.             FA_Client_Author,      'Olivier Laviale (lotan9@aol.com)',
  28.             FA_Client_Description, 'Demonstrate the use of custom classes.',
  29.             FA_Client_Base,        'CLASS1',
  30.  
  31.             Child, w := WindowObject,
  32.                FA_ID,           "MAIN",
  33.                FA_Window_Title, 'A Simple Custom Class',
  34.  
  35.                Child, VGroup,
  36.                   Child, F_NewObjA(cc.id,[TextFrame, TextBack, FA_Inner,[4,2,4,2]:CHAR, NIL]),
  37.                End,
  38.             End,
  39.          End
  40.  
  41.          IF c
  42.             F_DoA(w,FM_Notify,[FA_Window_CloseRequest,TRUE, c,2,FM_Client_ReturnID,FV_Client_Quit])
  43.             F_Set(w,FA_Window_Open,TRUE)
  44.  
  45.             F_DoA(c,FM_Client_Run,NIL)
  46.  
  47.             F_DisposeObj(c)
  48.          ENDIF
  49.  
  50.          F_RemoveClass(cc)
  51.       ELSE
  52.          WriteF('Unable to create custom class\n')
  53.       ENDIF
  54.  
  55.       CloseLibrary(feelinbase)
  56.    ELSE
  57.       WriteF('Unable to open feelin.library\n')
  58.    ENDIF
  59. ENDPROC
  60.  
  61. /*
  62.    Here is the beginning of our simple new class...
  63.  
  64.    This is an example for the simplest possible  Feelin  class.  It's  just
  65.    some  kind  of  custom image and supports only two methods: FM_AskMinMax
  66.    and FM_Draw.
  67.  
  68.    This class is realy simple and do not requires any instance data.
  69. */
  70.  
  71. PROC myDispatcher(cl=A2:PTR TO feelinClass,obj=A0:PTR TO feelinObject,method=D0,args=A1:PTR TO LONG)
  72. /*
  73.    Here comes the dispatcher for our custom class. We  only  need  to  care
  74.    about  FM_AskMinMax  and  FM_Draw  in  this  simple case. Unknown/unused
  75.    methods are passed to the superclass immediately.
  76. */
  77.    sys_RGlob()
  78.  
  79.    SELECT method
  80.       CASE FM_AskMinMax ; myAskMinMax(cl,obj)
  81.       CASE FM_Draw      ; myDraw(cl,obj,args)
  82.       DEFAULT           ; RETURN F_SuperDoA(cl,obj,method,args)
  83.    ENDSELECT
  84. ENDPROC 
  85. PROC myAskMinMax(cl,obj:PTR TO feelinObject)
  86. /*
  87.    FM_AskMinMax will be called before  the  window  is  opened  and  before
  88.    layout  takes place. We need to tell Feelin the minimum and maximum size
  89.    of our object.
  90. */
  91.  
  92.    _minw(obj) += 100 ; _maxw(obj) := 500
  93.    _minh(obj) +=  40 ; _maxh(obj) := 300
  94.  
  95.    F_SuperDoA(cl,obj,FM_AskMinMax,NIL)
  96. ENDPROC
  97. PROC myDraw(cl,obj:PTR TO feelinObject,d:PTR TO FS_Draw)
  98.    DEF i,c,rp,x1,y1,x2,y2
  99.  
  100.    /*
  101.       let our superclass draw itself first, Area class would e.g. draw  the
  102.       frame  and  clear  the  whole region. What it does exactly depends on
  103.       flags.
  104.    */
  105.  
  106.    F_SuperDoA(cl,obj,FM_Draw,d)
  107.  
  108.    -> Ok, everything ready to render...
  109.  
  110.    rp := _rp(obj)
  111.    x1 := _mx(obj) ; x2 := _mx2(obj)
  112.    y1 := _my(obj) ; y2 := _my2(obj)
  113.    c  := FV_Pen_Shine
  114.  
  115.    FOR i := x1 TO x2 STEP 5
  116.       _APen(_pen(obj,c))
  117.       _Move(x1,y2); _Draw(i,y1)
  118.       _Move(x2,y2); _Draw(i,y1)
  119.  
  120.       INC c ; IF c = FV_Pen_Highlight THEN c := FV_Pen_Shine
  121.    ENDFOR
  122. ENDPROC
  123.